package com.btobtob.a.biz.user.grpc;

import com.btobtob.a.biz.user.converter.Demo3Converter;
import com.btobtob.a.biz.user.entity.Demo3;
import com.btobtob.a.biz.user.protocol.Demo3Grpc;
import com.btobtob.a.biz.user.protocol.Demo3Reply;
import com.btobtob.a.biz.user.protocol.Demo3Request;
import io.grpc.stub.StreamObserver;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Slf4j
public class Demo3Impl extends Demo3Grpc.Demo3ImplBase {

    private static final Logger logger = LoggerFactory.getLogger(Demo3Impl.class);

    @Resource
    private Demo3Converter demo3Converter;

    @Override
    public void post3(Demo3Request req, StreamObserver<Demo3Reply> responseObserver) {

        Demo3 demo3 = demo3Converter.from(req);

        demo3.setTemperatureF(32 + (int)(req.getTemperatureC() / 0.5556));

        Demo3Reply reply = demo3Converter.to(demo3);

//        Demo3Reply.Builder builder = Demo3Reply.newBuilder();
//        builder.setId(req.getId())
//                .setDatetime(req.getDatetime())
//                .setTemperatureC(req.getTemperatureC())
//                .setTemperatureF(32 + (int)(req.getTemperatureC() / 0.5556))
//                .setSummary(req.getSummary());
//        Demo3Reply reply = builder.build();
        responseObserver.onNext(reply);
        responseObserver.onCompleted();
    }
}
